﻿#include "ar8030_callback_helper.h"
#include <iostream>

// #define HELP_DBG

static void callback_helper(void* arg, void* usr)
{
#ifdef HELP_DBG
    printf("callback !!! %p\n", usr);
#endif
    evt_callback* prv = (evt_callback*)usr;
    prv->run(arg);
}

AR8030_API int set_cb(bb_dev_handle_t* pdh, int evt, evt_callback* pcb)
{
    bb_set_event_callback_t cb;
    cb.callback = callback_helper;
    cb.event    = (bb_event_e)evt;
    cb.user     = pcb;
#ifdef HELP_DBG
    printf("callback !!! %p\n", pcb);
#endif
    int ret = bb_ioctl(pdh, BB_SET_EVENT_SUBSCRIBE, &cb, 0);

    if (ret) {
        printf("set callback err!\n");
        return -1;
    }
    printf("set evt %d callback ok!\n", evt);

    return 0;
}
